package mystia.lorelei.app.entity;


import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import mystia.lorelei.app.entity.dto.PurchaseDTO;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * 订单表(Purchase)表实体类
 *
 * @author gy_fangtao
 * @since 2023-09-16 16:39:43
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "purchase")
public class Purchase implements Serializable {
	@Serial
	private static final long serialVersionUID = -89511987577907393L;
	
	/**
	 * ID
	 */
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	/**
	 * 会员ID/客户ID
	 */
	@Column(name = "member_id")
	private Integer memberId;
	/**
	 * 订单内容
	 */
	@Column(name = "content")
	private String content;
	/**
	 * 总价
	 */
	@Column(name = "total_price")
	private BigDecimal totalPrice;
	/**
	 * 评分/满意度
	 */
	@Column(name = "score")
	private Integer score;
	
	@Column(name = "time")
	private Timestamp time;
	
	public Purchase(PurchaseDTO purchaseDTO) {
		this.id = purchaseDTO.getId();
		this.memberId = purchaseDTO.getMemberId();
		
		String str = purchaseDTO.getPurchaseItems().toString();
		this.content = str.substring(1,str.length()-1);
		this.totalPrice = purchaseDTO.getTotalPrice();
		this.score = purchaseDTO.getScore();
		this.time = purchaseDTO.getTime();
	}
}

